/*
 * application.h
 *
 *  Created on: 2009-1-6
 *      Author: fanliangliang
 */

#ifndef APPLICATION_H_
#define APPLICATION_H_

#include "toxic.h"
#include "common_struct.h"
#include <map>

using toxic::Thread;
using toxic::Appender;
using toxic::Log;
using std::map;

// forward declaration
class JobGenerator;
class Compressor;
class FileSender;
class XmlConfig;

class Application {
public:
	Application();
	~Application();

	void load(const string& xmlfile);
	void start();
	void stop();

	ostream& print(ostream& out) const;

private:
	void loadLog(XmlConfig& config);
	void loadRules(XmlConfig& config);
	void loadItems(XmlConfig& config);
	void startLog();
	void stopLog();
	void startWorkerThread();
	void stopWorkerThread();

private:
	typedef map<string, Rule*> NameRuleMap;

	Log::Level level_;
	vector<Appender*> appenders_;

	NameRuleMap rules_;
	vector<Item*> items_;

	JobGenerator* generator_;
	Compressor* compressor_;
	FileSender* sender_;
	bool isRunning_;
};

ostream& operator<<(ostream& out, const Application& app);

#endif /* APPLICATION_H_ */
